﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using OfficeOpenXml;

namespace HRProject.Code.FAO
{
    public class BaseExcelExporter
    {
        protected ExcelPackage excelPackage;
        protected ExcelWorksheet xlWorkSheet;
        protected object misValue = System.Reflection.Missing.Value;

        protected virtual void Export()
        {
            try
            {
                excelPackage.Save();
            }
            catch (Exception exp)
            {
                Console.Out.WriteLine(exp.Message);
            }

            releaseObject(excelPackage);
            releaseObject(xlWorkSheet);

            //MessageBox.Show("File created !");
        }

        private void releaseObject(object obj)
        {
            try
            {
                excelPackage.Dispose();
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                Console.Out.WriteLine("Unable to release the Object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }

        public void Dispose()
        {
            releaseObject(excelPackage);
            releaseObject(xlWorkSheet);
        }
    }
}
